package com.learn.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 实现线程的方式的三种方式
 */
public class DemoThread25110201 {

    public static void main(String[] args) {
        new DemoThread("DemoThread").start();
        new Thread(new DemoRunnable(), "DemoRunnable").start();
        ExecutorService executorService= Executors.newFixedThreadPool(3);
        DemoCallable demoCallable = new DemoCallable();
        executorService.submit(demoCallable);
        executorService.shutdown();
    }
}

/**
 * 继承Thread
 */
class DemoThread extends Thread{
    public DemoThread(){
        super();
    }
    public DemoThread(String threadName){
        super(threadName);
    }
    @Override
    public void run(){
        System.out.println(Thread.currentThread().getName()+"： is running...");
    }
}

/**
 * 实现Runnable
 */
class DemoRunnable implements Runnable{
    @Override
    public void run(){
        System.out.println(Thread.currentThread().getName()+"： is running...");
    }
}

/**
 * 实现Callable
 */
class DemoCallable implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"： is running...");
        return 1;
    }
}